package com.srd.phone.activity;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.widget.ExpandableListView;

import com.android.volley.VolleyError;
import com.shengrongdai.srd.R;
import com.srd.phone.adapter.MyAwardAdapter;
import com.srd.phone.bean.GroupData;
import com.srd.phone.bean.MyAward;
import com.srd.phone.mvp.presenters.UtilPresenter;
import com.srd.phone.utils.Constants;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的奖励
 */
public class MyAwardActivity extends BaseActivity {

    private ExpandableListView expandableListView = null;
    private MyAwardAdapter adapter = null;
    private List<GroupData> mList = new ArrayList<GroupData>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutViewId());

        initView();
        initData();
    }

    private int getLayoutViewId(){
        return R.layout.activity_my_award;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void initView() {
        tv_common_title.setText("我的奖励");
        expandableListView = (ExpandableListView)findViewById(R.id.expandableListView);

    }

    private UtilPresenter utilPresenter = null;
    public void initData() {
        adapter = new MyAwardAdapter(this, mList);
        expandableListView.setAdapter(adapter);
        expandableListView.setGroupIndicator(null);

        presenter = new UtilPresenter(requestQueue, this);
        utilPresenter = (UtilPresenter)presenter;
        setUrlArrs(Constants.MY_AWARD);
        getData();
    }

    private void getData(){
        utilPresenter.noParams(Constants.MY_AWARD);
    }

    @Override
    public void returnData(String tag, String data) {
        super.returnData(tag, data);
        if(Constants.MY_AWARD.equals(tag)){
            adapter.setDataSoucre(MyAward.parseData(data));
        }
    }

    @Override
    public void onError(String tag, VolleyError error) {
        super.onError(tag, error);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
